import logging
import os
import datetime


# save images of an episode
def save_imgs():
    pass


# create a logger
def get_logger(cfg, type):
    # create a logger
    logger = logging.getLogger(f'{cfg.LOG.LOGGER_NAME}')
    logger.setLevel(logging.INFO)

    log_root = os.path.join(cfg.ROOT, cfg.NAME, type)
    if not os.path.exists(log_root):
        os.makedirs(log_root)

    now = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')

    log_path = os.path.join(log_root, f'{now}.log ')

    # create a handler
    handler = logging.FileHandler(filename=log_path, mode='a')
    logger.addHandler(handler)

    logger.info('=================== config ===================')
    logger.info(cfg)
    logger.info('==============================================')

    # create a formatter
    formatter = logging.Formatter("[%(asctime)s | %(levelname)s%(message)s ",
                                  datefmt='%H:%M:%S')

    handler.setFormatter(formatter)
    logger.addHandler(handler)

    return logger
